package com.repair.user.service.impl;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.repair.api.user.constant.UserOperateType;
import com.repair.base.exception.SystemErrorCode;
import com.repair.base.exception.SystemException;
import com.repair.user.mapper.UserOperateStreamMapper;
import com.repair.user.pojo.entity.User;
import com.repair.user.pojo.entity.UserOperateStream;
import com.repair.user.service.UserOperateStreamService;
import org.springframework.stereotype.Service;

/**
 * @author chunyu
 * @since 2024/9/21,17:11
 */
@Service
public class UserOperateStreamServiceImpl extends ServiceImpl<UserOperateStreamMapper, UserOperateStream> implements UserOperateStreamService {

    @Override
    public long insertStream(User user, UserOperateType type) {
        UserOperateStream userOperateStream = new UserOperateStream();
        userOperateStream.setParam(JSON.toJSONString(user));
        userOperateStream.setType(type.name());
        userOperateStream.setUserId(user.getId().toString());
        int i = baseMapper.insert(userOperateStream);
        if (i == 0) {
            throw new SystemException(SystemErrorCode.INSERT_FAILED);
        }
        return 1;
    }
}
